package com.jm.bishe.controller;


import com.auth0.jwt.interfaces.DecodedJWT;
import com.jm.bishe.entity.*;
import com.jm.bishe.mapper.UserMapper;
import com.jm.bishe.service.Impl.RoomServiceImpl;
import com.jm.bishe.utils.JwtTokenUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/sys/room")
public class RoomController {


    @Autowired
    private RoomServiceImpl roomService;


    @PostMapping("/addRoom")
    @ResponseBody
    public Result addRoom(@RequestBody RoomAdd roomAdd, @CookieValue("token") String token){
        return roomService.addRoom(roomAdd,JwtTokenUtil.getId(token));
    }

    @GetMapping("/queryAllRoom")
    @ResponseBody
    public Result queryAllRoom(@CookieValue("token") String token){
        return roomService.queryAllRoom(JwtTokenUtil.getId(token));
    }


    @GetMapping("/queryType")
    @ResponseBody
    public Result queryRoomByType(@RequestParam("roomType") int selectRoomType,@CookieValue("token") String token){
        String roomType;
        switch (selectRoomType){
            case 1:roomType="单人房";break;
            case 2:roomType="双人房";break;
            case 3:roomType="大床房";break;
            default:
                return Result.falure(1003,"请选择要查询的房型",null);
        }
        return roomService.queryRoomByType(roomType,JwtTokenUtil.getId(token));
    }

    @GetMapping("/queryRoomById")
    @ResponseBody
    public Result queryRoomById(@RequestParam("queryRoomId")String roomId,@CookieValue("token") String token){
        return roomService.queryRoomById(roomId,JwtTokenUtil.getId(token));
    }


    @PostMapping("/reserveRoom")
    @ResponseBody
    public Result reserveRoom(@RequestBody RoomReserve roomReserve,@CookieValue("token") String token){
        return roomService.reserveRoom(roomReserve,JwtTokenUtil.getId(token));
    }


    @GetMapping("/roomLock")
    @ResponseBody
    public Result roomLock(@RequestParam("lock")boolean lock,@RequestParam("roomId")String roomId,@CookieValue("token") String token){
        return roomService.lockRoom(lock,roomId,JwtTokenUtil.getId(token));
    }


    @PostMapping("/createDiscount")
    @ResponseBody
    public Result createDiscount(@RequestBody DiscountBody discountBody,@CookieValue("token") String token){
        return roomService.createDiscount(discountBody.getRoomNumber(),discountBody.getRoomPrice(),discountBody.getRoomType(),JwtTokenUtil.getId(token));
    }


    @GetMapping("/queryDiscount")
    @ResponseBody
    public Result queryDiscount(@CookieValue("token") String token){
        return roomService.queryDiscount(JwtTokenUtil.getId(token));
    }


    @GetMapping("/checkIn")
    @ResponseBody
    public Result roomCheckIn(@RequestParam("roomId") String roomID,@RequestParam("realName") String realName ,@RequestParam("IDNumber") String IDNumber,@CookieValue("token") String token){
        return roomService.roomCheckIn(roomID,realName,IDNumber,JwtTokenUtil.getId(token));
    }
}
